package app.ui;

import game.components.AppUtilities;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JFrame;


public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8924308466844158184L;

	protected GridBagConstraints constraints;
	private AppUtilities appUtilities;

	protected PlayingScreenUi playingScreenUi;

	public MainFrame(AppUtilities appUtilities) {
		super("Main Frame");

		this.getContentPane().setLayout(new GridBagLayout());
		this.constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.BOTH;
		constraints.weightx = 1;
		constraints.weighty = 1;

		// set application utilities
		this.appUtilities = appUtilities;

		setDefaultCloseOperation(EXIT_ON_CLOSE);
		initialize();
		addComponents();
	}

	private void addComponents() {
		this.playingScreenUi = new PlayingScreenUi(this);
		add(playingScreenUi);
	}

	public void initialize() {
		this.setUndecorated(true);
		Dimension dimention = new Dimension(810, 601);
		setPreferredSize(dimention);
		setMinimumSize(dimention);
		setLocation(120, 80);
	}

	@Override
	public Component add(Component comp) {
		if (comp instanceof AbsCommonPanel) {
			AbsCommonPanel mPanel = (AbsCommonPanel) comp;
			mPanel.makeThisAutoResize();
			this.getContentPane().add(comp, getConstraints());
			return comp;
		}

		return super.add(comp);
	}

	public GridBagConstraints getConstraints() {
		return constraints;
	}

	public AppUtilities getAppUtilities() {
		return appUtilities;
	}

	public void setAppUtilities(AppUtilities appUtilities) {
		this.appUtilities = appUtilities;
		this.playingScreenUi.setAppUtilities(appUtilities);
	}
}
